import type { AdColumn } from '@/components/AdVxeTable';

import { getDeviceAlarmStatusEnumSchema } from '@/enums/iot/deviceAlarmStatusEnum';
import { getDeviceVaribaleStatusEnumSchema } from '@/enums/iot/deviceVaribaleStatusEnum';
import { getValueTypeEnumSchema } from '@/enums/iot/valueTypeEnum';
import { useI18n } from '@/hooks/web/useI18n';

const valueTypeEnumSchema = getValueTypeEnumSchema();
const deviceVaribaleStatusEnumSchema = getDeviceVaribaleStatusEnumSchema();
const deviceAlarmStatusEnumSchema = getDeviceAlarmStatusEnumSchema();

const { t } = useI18n();

export const columns: AdColumn[] = [
  {
    title: t('entity.idTitle'),
    field: 'Id',
    width: 150,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'integer',
  },
  {
    title: t('iot.route.state.variable.statusText'),
    field: 'Status',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'enum',
    enumData: deviceVaribaleStatusEnumSchema,
  },
  {
    title: t('iot.route.state.variable.deviceIdText'),
    field: 'DeviceId',
    width: 150,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'Variable.DeviceId',
    dataType: 'integer',
  },
  {
    title: t('iot.route.state.variable.deviceNameText'),
    field: 'DeviceName',
    width: 200,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'Variable.Device.Name',
    // filterJoin: {
    //   entityType: 'EaCloud.IoT.Entities.Device,EaCloud.IoT.Core',
    //   filterField: 'Name',
    //   selectField: 'Id',
    // },
    dataType: 'string',
  },
  {
    title: t('iot.route.state.variable.variableIdText'),
    field: 'VariableId',
    width: 150,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'integer',
  },
  {
    title: t('iot.route.state.variable.variableNameText'),
    field: 'VariableName',
    width: 200,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'Variable.Name',
    dataType: 'string',
  },
  {
    title: t('iot.route.state.variable.valueText'),
    field: 'Value',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('iot.route.state.variable.valueTypeText'),
    field: 'ValueType',
    width: 90,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'enum',
    enumData: valueTypeEnumSchema,
  },
  {
    title: t('iot.route.state.variable.messageText'),
    field: 'Message',
    width: 200,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('iot.route.state.variable.timestampText'),
    field: 'Timestamp',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
  {
    title: t('iot.route.state.variable.createdTimeText'),
    field: 'CreatedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
  {
    title: t('iot.route.state.variable.endedTimeText'),
    field: 'EndedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
  {
    title: t('iot.route.state.variable.elapsedText'),
    field: 'Elapsed',
    // width: 120,
    minWidth: 120,
    formVisible: true,
    formEditable: false,
    filterable: false,
    dataType: 'number',
  },
  {
    title: t('iot.route.state.variable.alarmStatusText'),
    field: 'AlarmStatus',
    width: 85,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'enum',
    enumData: deviceAlarmStatusEnumSchema,
  },
];
